//
//  PywDisclaimerViewController.m
//  PywSdk
//
//  Created by Ampaw on 2017/8/1.
//  Copyright © 2017年 Jade. All rights reserved.
//

#import "PywDisclaimerViewController.h"
#import "PywMasonry.h"
#import "PywAppInfo.h"
#import "UIButton+Pyw.h"
#import "UIImage+Pyw.h"
#import "MutableDictionary.h"

@interface PywDisclaimerViewController ()<UIWebViewDelegate>
@property (nonatomic, strong) UIWebView *webView;
@property (nonatomic, strong) UIButton  *backBtn;             // 返回注册 按钮

@end

@implementation PywDisclaimerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setUp];
}

- (void)setUp
{
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.navigationController.interactivePopGestureRecognizer.enabled = NO; // 禁止系统的手势返回
    
    [self.view addSubview:self.webView];
    [self.webView mas_makeConstraints:^(PywMASConstraintMaker *make) {
        make.top.right.left.offset(0);
        make.bottom.offset(-44);
    }];
    
    // 拼接“免责声明”地址，并加载
    NSString *urlStr = [NSString stringWithFormat:@"%@/%@",mianZeShengMingUrl,[PywAppInfo sharedAppInfo].gameId];
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlStr]
                                                  cachePolicy:NSURLRequestUseProtocolCachePolicy
                                              timeoutInterval:20];
    NSMutableURLRequest *mutableRequest = [request mutableCopy];
    request = [mutableRequest copy];
    [self.webView loadRequest:request];
    
    // 添加底部控件
    [self.view addSubview:self.backBtn];
    WEAK_SELF;
    [self.backBtn mas_makeConstraints:^(PywMASConstraintMaker *make) {
        STRONG_SELF(weakSelf);
        make.centerX.offset(0);
        make.left.bottom.right.equalTo(strongSelf.view);
        make.height.mas_equalTo(44);
    }];
}

#pragma mark - UIWebViewDelegate
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//    NSString *params = [NSString stringWithFormat:@"ios_game:%@",[PywAppInfo sharedAppInfo].gameId];
//    [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"getGameId('%@')",params]];
}

#pragma mark - Action
/// 选择 返回注册
- (void)selectNextButtonAction:(UIButton *)sender
{
    [self dismissViewControllerAnimated:YES completion:NULL];
}


#pragma mark - Lazy
- (UIWebView *)webView
{
    if (!_webView) {
        _webView = [[UIWebView alloc] init];
        _webView.delegate = self;
        _webView.scalesPageToFit = YES;
    }
    return _webView;
}

- (UIButton *)backBtn
{
    if (!_backBtn) {
        _backBtn = [UIButton buttonWithBackgroundColor:UIColorFromRGB(0xFFBC00)
                                          cornerRadius:0
                                            titleColor:[UIColor whiteColor]
                                    titleLabelFontSize:18
                                                 title:@"返回注册"];
        [_backBtn addTarget:self action:@selector(selectNextButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [_backBtn setAccessibilityIdentifier:@"common_disclaimerback"];
    }
    return _backBtn;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
